clearvars -except Globaloption option

%% Saving parameter estimates to automatically update the paper
fID = fopen(['../../results/tables_main/US/pre1946/Table_pre_us_twoVAR_break.tex'], 'w');

%% ONE VAR with break Results

load 'MAT/res_annual_VAR_nodebt_US_pre1860.mat';

%X2 mean

fprintf(fID, '\\newcommand{\\preCivilVarMeanh}{%4.2f}\n', 100 * mean(deltalogtau));
fprintf(fID, '\\newcommand{\\preCivilVarMeani}{%4.2f}\n', mean(log(taxrevgdp)));
fprintf(fID, '\\newcommand{\\preCivilVarMeanj}{%4.2f}\n', 100 * mean(deltalogg));
fprintf(fID, '\\newcommand{\\preCivilVarMeank}{%4.2f}\n', mean(log(spendgdp)));
fprintf(fID, '\\newcommand{\\preCiviltaxrevgdp}{%4.2f}\n', 100 * mean(taxrevgdp));
fprintf(fID, '\\newcommand{\\preCivilspendgdp}{%4.2f}\n', 100 * mean(spendgdp));

load MAT/benchmark_US_pre1860.mat
upper_ts = exp(pxbar) * (taxrevgdp - spendgdp);
fprintf(fID, '\\newcommand{\\preCivilkzerox}{%4.2f}\n', k0x);
fprintf(fID, '\\newcommand{\\preCivilkonex}{%4.2f}\n', k1x);
fprintf(fID, '\\newcommand{\\preCivilmeanpvsurplus}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\preCivilmeansurpluszeroz}{%4.2f}\n', mean(upper));
fprintf(fID, '\\newcommand{\\preCivilmeanpvsurpluspct}{%4.2f}\n', 100 * mean(s));
fprintf(fID, '\\newcommand{\\preCivilmeansurpluszerozpct}{%4.2f}\n', 100 * mean(upper));
fprintf(fID, '\\newcommand{\\preCivilpdgdp}{%4.2f}\n', mean(exp(pxbar)));
fprintf(fID, '\\newcommand{\\preCivilpdxbar}{%4.2f}\n', pxbar);
fprintf(fID, '\\newcommand{\\preCivilvr}{%4.2f}\n', mean(upper_ts));
fprintf(fID, '\\newcommand{\\preCivilgdpreturn}{%4.2f}\n', 100 * mean(gdpreturn));
fprintf(fID, '\\newcommand{\\preCivildebtgdp}{%4.2f}\n', nanmean(gdebt(2:end)));
fprintf(fID, '\\newcommand{\\preCivildebtgdppct}{%4.2f}\n', 100 * nanmean(gdebt(2:end)));

fprintf(fID, '\\newcommand{\\preCivilpvstodebt}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt(2:end)));

fprintf(fID, '\\newcommand{\\preCivilsurpluspct}{%4.2f}\n', 100 * (mean(taxrevgdp) - mean(spendgdp)));
A = corrcoef([gdebt(2:end) s'], 'rows', 'pairwise');

fprintf(fID, '\\newcommand{\\preCivilcorrpvsdebt}{%4.2f}\n', A(2));
fprintf(fID, '\\newcommand{\\preCiviluppertodebt}{%4.2f}\n', 100 * upper / nanmean(gdebt(2:end)));
fprintf(fID, '\\newcommand{\\preCivilcft}{%4.2f}\n', mean(exp(CFT)));
fprintf(fID, '\\newcommand{\\preCivilcfg}{%4.2f}\n', mean(exp(CFG)));
fprintf(fID, '\\newcommand{\\preCivildr}{%4.2f}\n', mean(exp(DR)));

%%
load 'MAT/res_annual_VAR_nodebt_US_post1860.mat';
fprintf(fID, '\\newcommand{\\postCivilVarMeanh}{%4.2f}\n', 100 * mean(deltalogtau));
fprintf(fID, '\\newcommand{\\postCivilVarMeani}{%4.2f}\n', mean(log(taxrevgdp)));
fprintf(fID, '\\newcommand{\\postCivilVarMeanj}{%4.2f}\n', 100 * mean(deltalogg));
fprintf(fID, '\\newcommand{\\postCivilVarMeank}{%4.2f}\n', mean(log(spendgdp)));
fprintf(fID, '\\newcommand{\\postCiviltaxrevgdp}{%4.2f}\n', 100 * mean(taxrevgdp));
fprintf(fID, '\\newcommand{\\postCivilspendgdp}{%4.2f}\n', 100 * mean(spendgdp));

load MAT/benchmark_US_post1860.mat
upper_ts = exp(pxbar) * (taxrevgdp - spendgdp);
fprintf(fID, '\\newcommand{\\postCivilkzerox}{%4.2f}\n', k0x);
fprintf(fID, '\\newcommand{\\postCivilkonex}{%4.2f}\n', k1x);
fprintf(fID, '\\newcommand{\\postCivilmeanpvsurplus}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\postCivilmeansurpluszeroz}{%4.2f}\n', mean(upper));
fprintf(fID, '\\newcommand{\\postCivilmeanpvsurpluspct}{%4.2f}\n', 100 * mean(s));
fprintf(fID, '\\newcommand{\\postCivilmeansurpluszerozpct}{%4.2f}\n', 100 * mean(upper));
fprintf(fID, '\\newcommand{\\postCivilpdgdp}{%4.2f}\n', mean(exp(pxbar)));
fprintf(fID, '\\newcommand{\\postCivilpdxbar}{%4.2f}\n', pxbar);
fprintf(fID, '\\newcommand{\\postCivilvr}{%4.2f}\n', mean(upper_ts));
fprintf(fID, '\\newcommand{\\postCivilcft}{%4.2f}\n', mean(exp(CFT)));
fprintf(fID, '\\newcommand{\\postCivilcfg}{%4.2f}\n', mean(exp(CFG)));
fprintf(fID, '\\newcommand{\\postCivildr}{%4.2f}\n', mean(exp(DR)));

fprintf(fID, '\\newcommand{\\postCivilgdpreturn}{%4.2f}\n', 100 * mean(gdpreturn));
fprintf(fID, '\\newcommand{\\postCivildebtgdp}{%4.2f}\n', nanmean(gdebt(2:end)));
fprintf(fID, '\\newcommand{\\postCivildebtgdppct}{%4.2f}\n', 100 * nanmean(gdebt(2:end)));

fprintf(fID, '\\newcommand{\\postCivilpvstodebt}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt(2:end)));

fprintf(fID, '\\newcommand{\\postCivilsurpluspct}{%4.2f}\n', 100 * (mean(taxrevgdp) - mean(spendgdp)));
A = corrcoef([gdebt(2:end) s'], 'rows', 'pairwise');

fprintf(fID, '\\newcommand{\\postCivilcorrpvsdebt}{%4.2f}\n', A(2));
fprintf(fID, '\\newcommand{\\postCiviluppertodebt}{%4.2f}\n', 100 * upper / nanmean(gdebt(2:end)));

%% Close File
fclose(fID);
